package com.qp;

import be.ac.ulg.montefiore.run.distributions.GaussianDistribution;
import be.ac.ulg.montefiore.run.jahmm.OpdfGaussian;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: bigmar
 * Date: 12/11/14
 * Time: 12:28 PM
 * To change this template use File | Settings | File Templates.
 */
public class OutputDistributionCalculator
{
    public static double[][] calculate(List<OpdfGaussian> gaussianList)
    {
        int numberOfModels=gaussianList.size();
        double[][] retVal=new double[numberOfModels][numberOfModels];
        for (int firstModelIndex=0; firstModelIndex<numberOfModels; ++firstModelIndex)
            for (int secModelIndex=0; secModelIndex<numberOfModels; ++secModelIndex)
            {

                double sumVars=gaussianList.get(firstModelIndex).variance()+gaussianList.get(secModelIndex).variance();

                double difExpectationPower2=gaussianList.get(firstModelIndex).mean()-gaussianList.get(secModelIndex).mean();
                difExpectationPower2*=difExpectationPower2;
                retVal[firstModelIndex][secModelIndex]=1/Math.sqrt(Math.PI*2)
                        /Math.sqrt(sumVars)
                        *Math.exp(-difExpectationPower2/sumVars/2);


            }
        return retVal;
    }

}
